package com.metaboot.demo.controller;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.metaboot.common.annotation.Log;
import com.metaboot.common.core.controller.BaseController;
import com.metaboot.common.core.domain.AjaxResult;
import com.metaboot.common.core.page.TableDataInfoPlus;
import com.metaboot.common.enums.BusinessType;
import com.metaboot.common.utils.poi.ExcelUtil;
import com.metaboot.demo.domain.DemoSchool;
import com.metaboot.demo.service.IDemoSchoolService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 主子表演示Controller
 * 
 * @author theodo
 * @date 2021-12-06
 */
@RestController
@RequestMapping("/demo/school")
@Api(value = "主子表演示演示控制器", tags = { "主子表演示演示" })
public class DemoSchoolController extends BaseController {
	@Autowired
	private IDemoSchoolService demoSchoolService;

	/**
     * 查询主子表演示列表
     */
    @ApiOperation("查询主子表演示列表")
    @PreAuthorize("@ss.hasPermi('demo:school:list')")
	@GetMapping("/list")
    public TableDataInfoPlus<DemoSchool> list(DemoSchool demoSchool){
    	return demoSchoolService.selectPageDemoSchoolList(demoSchool);
    }

	/**
	 * 导出主子表演示列表
	 */
	@PreAuthorize("@ss.hasPermi('demo:school:export')")
	@Log(title = "主子表演示", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, DemoSchool demoSchool) {
		List<DemoSchool> list = demoSchoolService.selectDemoSchoolList(demoSchool);
		ExcelUtil<DemoSchool> util = new ExcelUtil<DemoSchool>(DemoSchool.class);
		util.exportExcel(response, list, "主子表演示数据");
	}

	/**
	 * 获取主子表演示详细信息
	 */
	@PreAuthorize("@ss.hasPermi('demo:school:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return AjaxResult.success(demoSchoolService.selectDemoSchoolById(id));
	}

	/**
	 * 新增主子表演示
	 */
	@PreAuthorize("@ss.hasPermi('demo:school:add')")
	@Log(title = "主子表演示", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody DemoSchool demoSchool) {
		return toAjax(demoSchoolService.insertDemoSchool(demoSchool));
	}

	/**
	 * 修改主子表演示
	 */
	@PreAuthorize("@ss.hasPermi('demo:school:edit')")
	@Log(title = "主子表演示", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody DemoSchool demoSchool) {
		return toAjax(demoSchoolService.updateDemoSchool(demoSchool));
	}

	/**
	 * 删除主子表演示
	 */
	@PreAuthorize("@ss.hasPermi('demo:school:remove')")
	@Log(title = "主子表演示", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(demoSchoolService.deleteDemoSchoolByIds(Arrays.asList(ids)));
	}
}
